package group2assignone.ucm.administrator;

import group2assignone.func.Authentication;
import group2assignone.model.Administrator;
import group2assignone.model.Manager;
import group2assignone.ucm.UCController;
import group2assignone.view.MainView;
import group2assignone.view.UITool;
import java.util.ArrayList;

/**
 *public class UCAdminLogin implements UCController
 * this is the use case controller for the login of an administrator
 * it recieves data from the main login UC
 * @author group2
 */
public class UCAdminLogin implements UCController {

    private Administrator adm;
    private MainView view;
    private Authentication auth;
    private boolean ok;
    ArrayList<Manager> manList = new ArrayList<Manager>();

    public UCAdminLogin(MainView view) {
        this.view = view;
    }

    /**
     * Use Case: AdminLogin
     * Pre-Condition: MainView UI
     * Post-Condition: UI is updated
     * 1. System authenticates recieved Admin Login data
     * 2. System enters the Admin Main interface
     * 1a.  - Administrator credentials recieved are indcorrect
     *     System displays error and returns to the main UI
     */
    public void run() {
        adm = new Administrator();
        auth = new Authentication();
        view.upload(adm);
        ok = auth.authAdmin(adm);

        if (ok) {
            UCUIAdminMainView ucmv = new UCUIAdminMainView();
            ucmv.run();
            view.dispose();
        } else {
            UITool.displayError(auth.getErrorMsg(), view);
        }
    }
}




